﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ReporterEngine
{
    public class TemplateNode
    {
        private CommandTypes _commandType;

        public TemplateNode Parent;

        private string _stringExpression;

        private List<TemplateNode> _childs = new List<TemplateNode>();

        private int _startPosition;
        private int _endPosition;
        //only for row
        public int EndGroupCommandPosition;

        private TemplateCommand _command = new TemplateCommand();

        //public int EndSectionPosition;

        public TemplateNode EndSectionNode;

        public List<TemplateNode> Childs
        {
            get { return _childs; }
            set { _childs = value; }
        }

        public CommandTypes CommandType
        {
            get { return _commandType; }
            set
            {
                _commandType = value;
               
                if(value == CommandTypes.Undefined)
                    this.HasError = true;

                if (value == CommandTypes.EndSection)
                    this.IsVisible = false;
            }
        }

        public string StringExpression
        {
            get { return _stringExpression; }
            set { _stringExpression = value; }
        }

        public TemplateCommand Command
        {
            get { return _command; }
            set { _command = value; }
        }

        public int StartPosition
        {
            get { return _startPosition; }
            set { _startPosition = value; }
        }

        public int EndPosition
        {
            get { return _endPosition; }
            set { _endPosition = value; }
        }

        public bool HasError
        {
            get
            {
                return _hasError;
            }
            set { _hasError = value; }
        }

        public bool IsVisible
        {
            get { return _isVisible; }
            set { _isVisible = value; }
        }

        private bool _hasError = false;

        private bool _isVisible = true;

        //public TemplateNode endcommand

        public MessageLogArgs GetLog()
        {
            var result = MessageLogArgs.Debug();

            result.Message = "TemplateNode : " + Command.CommandName;
            result.Message += "TemplateNode index: " + Command.Index;
            result.Message += "TemplateNode Query: " + Command.Query;
            
            return result;
        }
    }
}
